package P1734;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Problema da disciplina de Estrutura de Dados e Complexidade de Algoritmos da
 * Pos Graduacao do Periodo 2011.1
 *
 * @see http://br.spoj.pl/problems/PLACAR/
 * @author Elenilson Vieira - 111100371 - elenilson[at]elenilsonvieira.com
 * @since 30 de marco de 2011
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line = null;
        int instance = 1;

        while((line = reader.readLine()) != null){
            int amount = Integer.parseInt(line);

            String unhappyDisapprovedName = null;
            int unhappyDisapprovedAmount = 11;
            
            for (int i= 0; i < amount; i++) {
                line = reader.readLine();
                String data[] = line.trim().split(" ");

                String currentName = data[0];
                int currentAmount = Integer.parseInt(data[1]);

                if(currentAmount < unhappyDisapprovedAmount ||
                        (currentAmount == unhappyDisapprovedAmount && currentName.compareTo(unhappyDisapprovedName) > 0)){
                    unhappyDisapprovedName = currentName;
                    unhappyDisapprovedAmount = currentAmount;
                }
            }

            System.out.println(String.format("Instancia %d\n%s", instance++, unhappyDisapprovedName));
        }
    }
}
